<?php

if(isset($_POST['operation']) && !empty($_POST['operation']) 
&& isset($_POST['captcha']) && !empty($_POST['captcha']) 
&& isset($_POST['email']) && !empty($_POST['email']) 
&& isset($_POST['sujet']) && !empty($_POST['sujet']) 
&& isset($_POST['message']) && !empty($_POST['message']) ) {
	
	$tab = explode(" ", $_POST['operation']);
	
	if( isset($tab[0]) && isset($tab[1]) && isset($tab[2]) ) {
		if($tab[1] == '+')
			$operation = $tab[0] + $tab[2];
		if($tab[1] == '-')
			$operation = $tab[0] - $tab[2];
		if($tab[1] == '*')
			$operation = $tab[0] * $tab[2];
	}
	
	$extra = "";
	
	if(isset($operation) && $operation == $_POST['captcha']) {
		$extra = '?send=1';
		 mail('alexandre.spriet@ensc.Fr', $_POST['sujet'], $_POST['message']); 
	} else if(isset($operation)){
		$extra = '?send=2';
	}
	
	
	$host  = $_SERVER['HTTP_HOST'];
	header("Location: http://$host$extra"); 

}	else {
	$host  = $_SERVER['HTTP_HOST'];
	$extra = '?send=3';
	header("Location: http://$host$extra");

}

?>